package org.lc.design.samples.case1.threadsafe;

import java.util.Properties;

/**
* 线程安全-双重检查机制实现
* @author lc
* @date 2024/7/8
*/
public class SafeConfigureManager {

    private static volatile SafeConfigureManager instance;

    private Properties properties;

    private SafeConfigureManager() {
        properties = new Properties();
        properties.setProperty("appName", "单例模式模拟");
        properties.setProperty("port", "8081");
    }

    public static SafeConfigureManager getInstance() {
        if(instance == null) {
            synchronized (SafeConfigureManager.class) {
                if(instance == null) {
                    instance = new SafeConfigureManager();
                }
            }
        }
        return instance;
    }

    public String getConfig(String key) {
        return properties.getProperty(key);
    }
}
